// pages/renshu/renshu.js
const app = getApp()
const util = require("../../utils/util");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        renshuList: [] //人数按照日期的统计数据
    },


    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getRenshu();
    },

    getRenshu(){
        const url = app.globalData.httpBase + "/api/xcx/getMonthData";
        const that = this;
        util.newhttp(url, 'POST').then(res => {
            const { data } = res;
            let tempArr = this.handleRenshuArray(data.data)
            this.setData({
                renshuList: tempArr
            })
        }).catch(err=>{
            console.log(err);
        })
    },

    // 处理数据
    handleRenshuArray(listObj){
        let listArray = []
        let znum = 0
        let wnum = 0

        for(let key in listObj){
            // 遍历数据
            let temp = listObj[key]['value']

            znum = 0
            wnum = 0
            temp.forEach((item, index) =>{
                for(let tempkey in item){
                    znum = znum + item[tempkey].zhong
                    wnum = wnum + item[tempkey].wan
                }
            })

            let tempObj = {
                'date': listObj[key]['month'],
                'znum': znum,
                'wnum': wnum
            }

            listArray.push(tempObj)
        }
        
        return listArray

    }

})